<template>
	<view>
		<view class="personalCenter">
			<view class="jx-content-box" style="margin-top: 20rpx;">
				<view class="jx-header-btm">
					<view class="jx-btm-item">
						<view style="width: 100%;">账户余额：{{(parseInt(normalAccount.balance) / 100).toFixed(2)}}</view>
						<view style="width: 100%;">待结算：{{(parseInt(normalAccount.frozen_balance) / 100).toFixed(2)}}</view>
					</view>
					
					<view>
						<view style="background: #FF7104;width: 130rpx;font-size: 30rpx;border-radius: 10rpx;text-align: center;color: #fff;margin-bottom: 20rpx;"
							@click="openUrl('/pages/hxt/balanceLogs')">明细</view>
						<view style="background: #FF7104;width: 130rpx;font-size: 30rpx;border-radius: 10rpx;text-align: center;color: #fff;"
							@click="openUrl('/pages/cash/index?cash_type=5')">提现</view>
					</view>
				</view>
			</view>
			

		</view>
		
		<view class="body">
			<view class="personalCenter-item" @click="herfHxtRegisterUrl">
				<jx-list-cell :arrow="true" padding="0" :lineLeft="false">
					<view class="jx-cell-header" style="height: 100rpx;">
						<view class="jx-cell-title" style="font-weight: 700;">{{sellerAccount.status == 2 && sellerAccount.account_id ? '收款账户详情' : '开通收款账户'}}</view>
					</view>
				</jx-list-cell>
			</view>
			
			<view class="personalCenter-item" @click="openUrl('/pages/hxt/account')">
				<jx-list-cell :arrow="true" padding="0" :lineLeft="false">
					<view class="jx-cell-header" style="height: 100rpx;">
						<view class="jx-cell-title" style="font-weight: 700;">结算账户</view>
					</view>
				</jx-list-cell>
			</view>
			
		</view>
		
		<view class="page-desc" @click="descVisible = true">
			<text>查看说明</text>
		</view>
		
		
		<u-popup v-model="descVisible" mode="top" length="100%" closeable>
			<view style="padding: 100rpx 20rpx 0;">
				<h2 style="text-align: center;">收款账户和结算账户的说明</h2>
				
				<view style="padding-top: 80rpx;">
						<text style="font-weight: 600;">收款账户：</text>主要用于收款，您推荐的用户进货付款时将使用您的主体信息进行收款。<br><br>
						<text style="font-weight: 600;">结算账户：</text>主要用于收益结算，不能进行收款。<br>当有推荐用户付款时，为确保收益正常发放，系统将自动为您开通结算账户。<br>自动开通结算账户有以下2种情况：<br>
						1.未开通收款账户时，系统默认使用注册手机号进行注册。<br>
						2.已开通收款账户时，系统默认使用收款账户信息注册。<br>
						<br><br>
						<text style="font-weight: 600;">收益结算：</text>系统统一通过结算账户进行结算，即提现成功后将打款到结算账户所绑定的银行卡。<br><br>
						
						<text style="font-weight: 600;">简单总结：需要修改提现银行卡，请点击 [结算账户] 进行添加银行卡和切换默认结算卡</text></text><br><br>
						
						<text style="font-weight: 600;font-size: 14pt;color:red">店主及以上身份必须开通收款账户，否则系统将禁止您进行提现。</text>
				</view>
			</view>
		</u-popup>
		
		
		
		
		<com-modal :custom="true" :show="accountOpenModal" padding="0" @cancel="closeHandler">
			<view class="jx-modal-title">账户激活</view>
			
			<view style="font-size: 10pt;padding: 10rpx 20rpx;text-align: center;">您的恒信通账户未激活，您需要填写银行卡信息来激活恒信通账户才可进行提现。注意该银行卡将用于后续的资金结算！</view>
			
			
			<view style="margin: 20rpx 0;">
		
				<view class="shopSetting-item">
					<view class="shopSetting-title">银行卡号</view>
					<view class="shopSetting-int">
						<input type="text" placeholder="填写银行卡号" v-model="accountOpenForm.accountCode"/>
					</view>
				</view>
		
				<view class="shopSetting-item">
					<view class="shopSetting-title">姓名</view>
					<view class="shopSetting-int">
						<input type="text" placeholder="填写持卡人的姓名" v-model="accountOpenForm.accountName"/>
					</view>
				</view>
				
				<view class="shopSetting-item">
					<view class="shopSetting-title">身份证号码</view>
					<view class="shopSetting-int">
						<input type="text" placeholder="填写持卡人身份证号码" v-model="accountOpenForm.idCode"/>
					</view>
				</view>
				
				
				<view class="shopSetting-item">
					<view class="shopSetting-title">手机号</view>
					<view class="shopSetting-int">
						<input type="text" placeholder="填写持卡人手机号" v-model="accountOpenForm.tel"/>
					</view>
				</view>
				
				<view style="margin-top: 20rpx;padding: 30rpx;">
					
					<view @click='autoAccountData' style="text-align: center;padding-bottom: 40rpx;font-size: 10pt;color:#ff7104;text-decoration: underline;">填入兰亭实名信息与默认银行卡</view>
					
					<button @click="accountOpen" style="background-color: #fcc80e;color: #fff;font-weight: 600;">确认激活</button>
				</view>
			</view>
			
		</com-modal>
	</view>
	
	
</template>

<script>
	import jxListCell from '@/components/list-cell/list-cell';
	export default {
		data(){
			return {
				type: 1,
				normalAccount:{
					balance:'0.00',
					frozen_balance:'0.00'
				},
				sellerAccount:{
					account_id:'',
					status:0,
					registerUrl:''
				},
				
				
				
				userHxt:{
					status:0,
					registerUrl:''
				},
				balanceInfo:{
					balance:'0.00',
					frozen_balance:'0.00'
				},
				
				
				
				
				accountStatus:'',
				accountOpenModal:false,
				accountOpenForm:{
					accountCode:'',
					accountName:'',
					idCode:'',
					tel:''
				},
			
			
			
				descVisible:false,
			
			}
		},
		components: {
			jxListCell
		},
		onLoad(opt){
			this.type = opt.type ?? 1;
		},
		async onShow(){
			uni.showLoading({title:'请稍后...',mask:true});
			await this.getHxtRegisterDetail();
			await this.hxtAccountInfo();
			uni.hideLoading();
		},
		methods: {
			
			openUrl(url) {
				uni.navigateTo({url})
			},
			
			async getHxtRegisterDetail(){
				let self = this;
				let res = await self.$http.request({url: self.$api.hxt.registerDetail,method:'post'});
				if(res.code == 0){
					Object.assign(self.normalAccount,res.data.normal);
					Object.assign(self.sellerAccount,res.data.seller);
					if(self.sellerAccount.extend){
						let extend = JSON.parse(self.sellerAccount.extend);
						self.sellerAccount.registerUrl = extend.registerUrl ? extend.registerUrl : '';
					}
					
				}
			},
			
			async herfHxtRegisterUrl(){
				let self = this;
				if(!self.sellerAccount.registerUrl){
					let data = {app_type:self.type};
					let res = await self.$http.request({url: self.$api.hxt.registerUrl,method:'post',showLoading:true,data});
					if(res.code != 0){
						uni.showToast({title:res.message,icon:'none',duration:3000})
						return;
					}
					self.sellerAccount.registerUrl = res.data.registerUrl;
				}
				// console.log(self.sellerAccount)
				// console.log('herfHxtRegisterUrl',self.userHxt);
				window.location.href = self.sellerAccount.registerUrl;
			},
			
			
			async hxtAccountInfo(){
				let self = this;
				let res = await self.$http.request({url:self.$api.hxt.hxtAccountInfo})
				if(res.code == 0 && res.data.status == 0){//有恒信通子账户，并且没有激活
					this.accountOpenModal = true;
					this.accountStatus = 0;
				}
				
			},
			closeHandler(){
				this.accountOpenModal = false;
				this.accountOpenForm={
					accountCode:'',
					accountName:'',
					idCode:'',
					tel:''
				}
			},
			async accountOpen(){
				let self = this;
				let res = await self.$http.request({url:self.$api.hxt.hxtAccountOpen,data:this.accountOpenForm,showLoading:true});
				if(res.code != 0){
					this.$http.toast(res.msg);
					return ;
				}
				this.$http.toast('激活成功');
				this.accountOpenModal = false;
			},
			async autoAccountData(){
				let self = this;
				let res = await self.$http.request({url:self.$api.hxt.lantingUserRealData,showLoading:true})
				if(res.code === 0){
					this.accountOpenForm.accountCode = res.data.bank_account;
					this.accountOpenForm.accountName = res.data.realname;
					this.accountOpenForm.idCode = res.data.cert_no;
					this.accountOpenForm.tel = res.data.mobile;
				}
			}
		}
	}
</script>

<style lang="scss">
	.personalCenter {
		width: 100%;
		overflow: hidden;
		background: url(https://cos.zaituan.com.cn/uploads/images/original/20250527/aadd7d58d75f1288777c673390c56ec7.jpg) no-repeat; 
		background-size: 100%;
	}
	.jx-content-box {
		width: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;
		// margin-top: 20rpx;
	}
	.jx-header-btm {
		border-radius: 12rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #000;
		background: #ffffff;
		margin-bottom: 20rpx;
		padding: 20rpx 40rpx;
	}
	
	
	.personalCenter-item {
		width: 100%;
		overflow: hidden;
		margin: 20upx 0 0 0;
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.jx-cell-header {
		width: 100%;
		// height: 100rpx;
		height: 70rpx;
		padding: 0 40rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #f3f3f3;
	}
	
	.jx-cell-title {
		font-size: 11pt;
		line-height: 30rpx;
		font-weight: 400;
		color: #333;
		font-weight: 600;
		letter-spacing: 1px;
	}
	

	.jx-modal-title {
		text-align: center;
		font-size: 34rpx;
		color: #333;
		padding-top: 20rpx;
		font-weight: bold;
	}
	.shopSetting-item {
		width: 90%;
		margin: 0 auto;
		border-bottom: 1rpx solid #888888;
		overflow: hidden;
		display: flex;
		justify-content: space-between
	}
	.shopSetting-title {
		height: 100rpx;
		line-height: 100rpx;
		margin-right: 20rpx;
		color: #000;
	}
	
	.shopSetting-int {
		height: 100rpx;
		max-width: 80%;
	}
	.shopSetting-int text{
		display: block;
		height: 100rpx;
		line-height: 100rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.shopSetting-int input {
		height: 100rpx;
		text-align: right;
	}



	.page-desc{
		position: fixed;
		bottom: 30vh;
		right: 0;
		background-color: #FF7104;
		color:#fff;
		padding: 10rpx 20rpx;
		border-top-left-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}
</style>
